<template>
  <el-dialog
    title="新增科目"
    class="subjectAdd_dialog gl_dialog_TitleLine gl_dl_footer"
    :visible.sync="dialogVisible"
    width="486px"
    :close-on-click-modal="false"
    @close="closeDialog"
  >
    <div class="gl_px_20">
      <el-form ref="form" class="gl_form_mini" size="medium" :model="vo" :rules="rules" label-position="top" label-width="80px">
        <el-form-item label="科目名称" prop="name">
          <el-input v-model="vo.name" placeholder="请输入科目名称" />
        </el-form-item>
        <el-form-item label="会员价（元）" prop="memberPrice">
          <el-input-number v-model="vo.memberPrice" placeholder="请输入会员价（元）" style="width:100%;" :controls="false" :precision="2" :min="0" :max="21474836" />
        </el-form-item>
        <el-form-item label="非会员价（元）" prop="nonMemberPrice">
          <el-input-number v-model="vo.nonMemberPrice" placeholder="请输入非会员价（元）" style="width:100%;" :controls="false" :precision="2" :min="0" :max="21474836" />
        </el-form-item>
        <template v-if="dialogMode === 'Exam'">
          <el-form-item label="证书名称" prop="certificateName">
            <el-input v-model="vo.certificateName" placeholder="请输入证书名称" />
          </el-form-item>
          <el-form-item label="证书等级" prop="certificateLevel">
            <el-input v-model="vo.certificateLevel" placeholder="请输入证书等级" />
          </el-form-item>
          <el-form-item label="证书类型" prop="certificateType">
            <el-input v-model="vo.certificateType" placeholder="请输入证书类型" />
          </el-form-item>
          <el-form-item label="必报科目" prop="isEntryRequired">
            <el-radio-group v-model="vo.isEntryRequired">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </template>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <!-- 取消按钮 -->
      <el-button size="mini" @click="closeDialog">取消</el-button>
      <!-- 保存按钮 -->
      <el-button type="primary" :loading="submitLoading" size="mini" @click="submitDialog">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { SiSTKWTrainCreateSubjectInput } from '@/lib/form/train/swaggerForm.js';
import { SubjectDialogAdd_Rules } from '@/lib/validate/configuration/index.js';

export default {
  props: {
    dialogMode: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      dialogVisible: false,
      submitLoading: false,
      vo: new SiSTKWTrainCreateSubjectInput(),
      rules: new SubjectDialogAdd_Rules()
    };
  },
  methods: {
    // 打开弹窗
    openDialog (options) {
      this.dialogVisible = true;
    },
    // 关闭弹窗
    closeDialog () {
      this.resetDialog();
      this.dialogVisible = false;
    },
    // 确认弹窗内的信息
    submitDialog () {
      this.$refs.form.validate(
        valid => {
          if (valid) {
            const _vo = JSON.parse(JSON.stringify(this.vo));
            this.$emit('onSubmit', _vo);
          }
        });
    },
    // 重置弹窗数据
    resetDialog () {
      this.$refs.form.resetFields();
    }
  }
};
</script>

<style>
.el-input-number .el-input__inner {
  text-align: left;
}
</style>

<style lang="scss" scoped>

</style>
